<?php
add_action('widgets_init', 'register_search_filter_widget'); // load widget

function register_search_filter_widget() { // register widget
    register_widget('search_filter');
}

class search_filter extends WP_Widget {// widget class {

    function search_filter() { 
    // widget setting | class name must be same function name
        $widget_ops = array('classname' => 'Lastest news-w', 'description' =>
            'Filter by Categories, store and coupon type');
        $control_ops = array(
            'width' => 250,
            'height' => 350,
            'id_base' => 'search_filter');
        $this->WP_Widget('search_filter', 'CouponX - Search filter by categories,store and coupon type', $widget_ops, $control_ops);
    }

    function widget($args, $instance) { 
        $categories = get_terms('store_category',array('hide_empty'=> false));
        ?>
        <!--Filter by Top Stores-->
            <div class="row-fluid filter-category">
                <div class="row-fluid filter-title">
                    <p>By Categories</p>
                </div>
                <div class="row-fluid categories_filter">
                    <?php foreach ($categories as $categorys){ 
                        $cat_id = $categorys->term_id;
                    ?>
                    <li>
                        <lable for="<?php echo $cat_id;?>">
                            <?php echo $categorys->name;?>
                            <input id="<?php echo $cat_id;?>" name="<?php echo $cat_id;?>" type="checkbox" value="<?php echo $cat_id;?>" />
                        </lable>
                    </li>
                    <?php }?>
                    
                </div>
            </div>
            <!--#Filter by Top Stores-->
            <!--Filter by Coupon Type-->
            
            <!--#Filter by Coupon Type-->
   
        
    <?php }
    function update($new_instance, $old_instance) { // update widget
        $instance = $old_instance;
        $instance['title'] = $new_instance['title'];
        return $instance;
    }

    function form($instance) { // form for the widget options
        ?>
        <div style="color: #333;">
            <p>        
                <label for="<?php echo $this->get_field_id('title'); ?>"><?php echo 'Title'; ?></label>
                <input type="text" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $instance['title']; ?>" style="width:90%;" />
            </p>                 
        </div>
        <?php
    }
}
?>
